/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package judf.delegate;



import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.InitialContext;
import java.util.Properties;
import javax.naming.NamingException;



/**
 *
 * @author Frank Gabriel Rodríguez Lee
 */

public class DelegateObjeto {

    protected DelegateObjeto(){        
    }


    //Patron Singleton
    public static synchronized DelegateObjeto getInstance(){
        if (gestionDelegate == null) {                        
            gestionDelegate = new DelegateObjeto();
        }
        return gestionDelegate;
    }

    public Object callGestionFacade(){
        Object sless = null;
        try {            
            sless = _ic.lookup(pathFacade);
        } catch (NamingException ex) {
            Logger.getLogger(DelegateObjeto.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println( "Error en la llamada del servicio" );
        }
        return sless;
    }     

    public void inicializaContexto() throws NamingException{
        Properties properties = new Properties();
        properties.setProperty("org.omg.CORBA.ORBInitialHost", host);
        properties.setProperty("org.omg.CORBA.ORBInitialPort", port);
        _ic = new InitialContext( properties );        
    }

    public String getPathFacade() {
        return pathFacade;
    }

    public void setPathFacade(String pathFacade) {
        this.pathFacade = pathFacade;
    }

    public void getServicio(){

    }
    //Variables que pueden ser modificadas
    public static String host;
    public static String port;
    private static DelegateObjeto gestionDelegate;

    protected InitialContext _ic;
    protected String pathFacade;
}
